package com.hopes.bizz.risk.applet.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopes.bizz.risk.applet.service.AppletMeasureTaskService;
import com.hopes.bizz.risk.control.dto.RiskMeasureTaskRecordDTO;
import com.hopes.bizz.risk.control.vo.RiskMeasureTaskRecordVO;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author yumr
 * @Description 小程序双体系排查任务
 * @time 2023/7/28 13:03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/appletMeasureTask")
@Tag(description = "appletMeasureTask", name = "小程序双体系排查接口")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AppletMeasureTaskController {


    private final AppletMeasureTaskService appletMeasureTaskService;

    /**
     * (小程序)双体系排查任务
     * @param page 分页对象
     * @param riskMeasureTaskRecord 隐患排查任务
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('control_risk_point_check_task_view')" )
    public R getAppMeasureTaskPage(Page page, RiskMeasureTaskRecordVO riskMeasureTaskRecord) {
        return R.ok(appletMeasureTaskService.selectPage(page, riskMeasureTaskRecord));
    }

    /**
     * （小程序）通过id查询隐患排查任务
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('control_risk_point_check_task_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(appletMeasureTaskService.getById(id));
    }

    /**
     * 提交隐患排查任务
     * @param measureTaskRecordDTO 提交隐患排查任务
     * @return R
     */
    @Operation(summary = "提交隐患排查任务" , description = "提交隐患排查任务" )
    @SysLog("提交隐患排查任务" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('control_risk_point_check_task_edit')" )
    public R submitTask(@RequestBody RiskMeasureTaskRecordDTO measureTaskRecordDTO) {
        return R.ok(appletMeasureTaskService.submitTask(measureTaskRecordDTO));
    }


    /**
     * 批量提交隐患排查任务
     */
    @Operation(summary = "批量提交隐患排查任务" , description = "批量提交隐患排查任务" )
    @SysLog("批量提交隐患排查任务" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('control_risk_point_check_task_edit')" )
    public R batchSubmitTask(@RequestBody Long[] ids) {
        return R.ok(appletMeasureTaskService.batchSubmitTask(ids));
    }

}
